package com.gitee.pifeng.monitoring.example;

import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;

import com.gitee.pifeng.monitoring.common.constant.AlarmLevelEnums;
import com.gitee.pifeng.monitoring.common.constant.MonitorTypeEnums;
import com.gitee.pifeng.monitoring.common.constant.ThreadTypeEnums;
import com.gitee.pifeng.monitoring.common.domain.Alarm;
import com.gitee.pifeng.monitoring.common.domain.Result;
import com.gitee.pifeng.monitoring.plug.Monitor;
import com.google.common.base.Charsets;

public class Main {

	public static void main(String[] args) {

		// 开启监控功能
		Monitor.start();

		// 业务埋点监控
		ScheduledExecutorService service = Monitor.buryingPoint(() -> {
			// 如果发现业务异常，则发送告警
			Alarm alarm = new Alarm();
			alarm.setAlarmLevel(AlarmLevelEnums.ERROR);
			alarm.setTitle("业务埋点监控");
			alarm.setTest(false);
			alarm.setCharset(Charsets.UTF_8);
			alarm.setMsg("测试普通maven程序业务埋点监控！");
			// alarm.setCode("001");
			alarm.setMonitorType(MonitorTypeEnums.CUSTOM);
			Result result = Monitor.sendAlarm(alarm);
			System.out.println("发送业务告警结果：" + result.toJsonString());
		}, 0, 1, TimeUnit.HOURS, ThreadTypeEnums.IO_INTENSIVE_THREAD);
		System.out.println(service.toString());

		// 防止主线程退出（测试代码才需要）
		while (true) {
		}
	}

}
